package com.bdqn.t296.noso.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.t296.noso.entity.Lrecord;
import com.bdqn.t296.noso.entity.Pay;
import com.bdqn.t296.noso.entity.Register;
import com.bdqn.t296.noso.service.LpayService;
import com.bdqn.t296.noso.service.RegisterService;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/hospital")
public class LpayController {
    @Resource
    LpayService lpayService;
    @Resource
    RegisterService registerService;
    @RequestMapping("/pay")
    public String pay(){
        return "/hospital/pay";
    }
    //查询和交款
    @RequestMapping("/selPay")
    @ResponseBody
    public Object selpay(Register register,Double money){
        System.out.println("传过来的值"+register.getRegisterid());
        System.out.println("传过来的金钱"+money);
        if(money!=null){

            register.setMoney(money);
            //修改预交款
            lpayService.updPay(register);
            //添加预交款记录
            lpayService.addPay(register);
        }

              List<Register> registers = registerService.selRegister(register);
            return registers;
}
//查询预交款记录
@RequestMapping("/selPays")
@ResponseBody
    public  Object selPays(Register register,@RequestParam(value = "pageIndex",required = false,defaultValue = "1") Integer pageIndex) { //当前显示的页码
        System.out.println("传进来的页数"+pageIndex);

    System.out.println("传过来的值22222"+register.getRegisterid());
        QueryWrapper<Pay> payQueryWrapper = new QueryWrapper<Pay>();
        payQueryWrapper.like("p.registerid",register.getRegisterid());
        System.out.println("pageIndex"+pageIndex);
        Page<Pay> page = new Page<Pay>(pageIndex, 3);
        IPage<Pay> paylist = lpayService.selPays(page,payQueryWrapper);
    for (Pay register2 : paylist.getRecords()) {//获得查询记录
        System.out.println();
        System.out.println("编号：" + register2.getRegisterid());
        System.out.println("姓名：" +  register2.getUserName());
        System.out.println("预交金额：" +  register2.getMoney());
        System.out.println("交款时间：" +  register2.getPayDate());
    }
        return paylist;
    }
    //查询已用多少
    @RequestMapping("/selSurplus")
    @ResponseBody
    public Object selSurplus(Lrecord lrecord){
        System.out.println("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
        List<Lrecord> list = lpayService.selSurplus(lrecord);
        return list;
    }
}
